<html><head>

<script language="Javascript" src="../gamelib/gamelib_core.js"></script>
<script language="Javascript" src="../gamelib/gamelib_sprites.js"></script>
<script language="Javascript" src="../gamelib/gamelib_mouse.js"></script>
<script language="Javascript" src="../gamelib/gamelib_sound.js"></script>
<script language="Javascript">

var mysound_flipflop=new Array(false,false,false,false);
var mysound=new Array();
var mybutton=new Array();

function init(){

	mysound[0]=new Sd_add_sound("../sound/canyon.mid");	// first, make 5 sound objects
	mysound[1]=new Sd_add_sound("../sound/clk.wav");
	mysound[2]=new Sd_add_sound("../sound/chord.wav");
	mysound[3]=new Sd_add_sound("../sound/jungle.wav");
	mysound[4]=new Sd_add_sound("../sound/chimes.wav");
	mysound[0].setVolume(80);	// set the volume for the midi soung to 80 (Default is 100);

	for(nn=0;nn<4;nn++){
		mybutton[nn]=new Sp_Sprite();			// now make some buttons
		mybutton[nn].setXlimits(0,200);
		mybutton[nn].setYlimits(0,200);
		mybutton[nn].setImage("../images/msi0.gif",32,32,6,1);	// (sprites with mouse)
		mybutton[nn].setFrame(0);
		mybutton[nn].moveTo(40+(nn*40),120);		// event triggers.
		mybutton[nn].onclickdown="stopplay("+nn+")";
		mybutton[nn].onclickup="buttonup("+nn+")";
		mybutton[nn].onmouseover="buttonover("+nn+")";
		mybutton[nn].onmouseout="buttonout("+nn+")";
		mybutton[nn].switchOn();				// switch the sprite on
	}

	mymouse=Ms_initmouse();		// enable the mouse events
	Gl_start();			// start the library! Never forget to do this!
}

function stopplay(x){	// this function starts or stops a sound on a button press
			// it also moves the button sprite, so it looks "pressed"
			// and changes the sprite to a green button image

	if(mysound_flipflop[x]) mysound[x].stop();
	else mysound[x].play();
	if(x<1) mysound_flipflop[x]=!mysound_flipflop[x];
	mybutton[x].moveTo(45+(x*40),125);
	mybutton[x].setFrame(2);
}

function buttonup(x){	// this function moves the button back to its normal place
			// and changes its image back to the normal blue button

	mybutton[x].moveTo(40+(x*40),120);
	mybutton[x].setFrame(0);
}

function buttonover(x){	// this function changes the button sprite's image to a white
			// button image

	mybutton[x].setFrame(5);
	mysound[4].play()
}

function buttonout(x){	// this function changes the button sprite's image back to blue

	mybutton[x].setFrame(0);
}


</script></head>

<body bgcolor="#000000" onload="init()">
<font color="#ffbb00" face="Arial" size=3>
<u>Sound library example 1</u><br><br>
<font size=2>
Click the buttons to start and stop their sounds<br>
When you move the mouse over them, you will<br>
also hear a click. Please wait a few seconds for<br>
the sounds to load up first though...
</font>
</font>
</body>
</html>